import 'package:flutter/material.dart';
import 'package:flutter_chat_ui/models/app_info_model.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:uuid/uuid.dart';

///
/// 初始化绑定getx controller
///
// class DefaultVoiceBindings extends Bindings {
//   @override
//   void dependencies() {
//     /// 初始化 VoiceController
//     Get.lazyPut(() => VoiceController(), fenix: true);
//   }
// }

///
/// 工具类
///
class Utils {
  /// 用于记录最后一条机器人回答内容的conversation_id
  static String? lastConversationId;

  /// 唯一标识userId
  static const String userId = 'hongbo';

  /// 唯一标识生成器
  static const Uuid _uuid = Uuid();

  /// 底部圆弧渐变高度
  static const double voiceBgGradientHeight = 200;

  /// 底部圆弧Voice Icon高度
  static const double voiceBgOvalHeight = 125;

  ///
  /// 获取 app 本地信息
  ///
  static Future<AppInfoModel> getAppInfo() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    // 创建自定义 app 本地信息模型
    return AppInfoModel(
      appName: packageInfo.appName,
      packageName: packageInfo.packageName,
      version: packageInfo.version,
      buildNumber: packageInfo.buildNumber,
    );
  }

  ///
  /// 跳转权限设置页
  ///
  static Future<bool> xOpenAppSettings() {
    return openAppSettings();
  }

  ///
  /// 判断是否为空字符串
  ///
  /// return 空：true，非空：false
  ///
  static bool isBlank(String? value) {
    if (value == null) {
      return true;
    }
    if (value.isEmpty) {
      return true;
    }
    // 去除字符串空格
    String rsValue = value.replaceAll(RegExp(" "), "");
    if (rsValue.isEmpty) {
      return true;
    }
    return false;
  }

  ///
  /// 获取唯一标识
  ///
  static String getUniqueId() {
    return _uuid.v4();
  }

  ///
  /// 毫秒级时间戳转年月日
  ///
  static String formatTime(int timestamp) {
    DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(timestamp);
    String formattedTime = "${dateTime.hour}:${dateTime.minute}";
    return formattedTime;
  }
}

///
/// 信息event类型枚举
///
enum MessageEventType {
  /// 机器人欢迎语
  welcome(event: 'welcome'),

  /// 机器人回复
  robot(event: 'message'),

  /// 主人消息
  master(event: 'master');

  final String event;

  const MessageEventType({
    required this.event,
  });
}

///
/// session会话更多属性枚举
///
enum ChatSessionMoreType {
  /// 重新命名
  rename,

  /// 删除
  delete,
}

///
/// 修理自动线
///
extension FixAutoLines on String {
  String fixAutoLines() {
    return Characters(this).join('\u{200B}');
  }
}
